<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Ajax_Milestone extends Controller {
    
	
	public function action_index()
	{
		$ret = Session::instance()->set('lover', 'To Anh');
		echo Debug::dump($ret);
		//echo ('In the session controler');
	}
	public function action_update_milestone_status($mile_id)
	{
		$cur_user_id = $_GET['cur_user_id'];
		$this->response->body(json_encode(array(
			'success' => TRUE
		)));
	}
	public function action_add_milestone()
	{
		$mile_data 				= $_POST;
		$mile_data['status']	= Helper_MyConst::STATUS_IN_PROGRESS;
		$mile_data['user_id']	= $mile_data['cur_user_id'];
		$owner_id 				= $_POST['owner_id'];
		
		unset($mile_data['owner_id']);
		unset($mile_data['cur_user_id']);
		
		$ret = Model::factory('milestone')->add_milestones($mile_data, $owner_id);
		if ($ret)
		{
			$ret_data = $_POST; $ret_data['id'] = $ret[0];
			$ret_array = array('success' => TRUE, 'data' => $ret_data);
		}
		else 
			$ret_array = array('success' => FALSE);
		$mile_data['user_id'] = Helper_Auth::instance()->get_user_id();
		//$ret = Model::factory('milestone')->add_milestones($mile_data);
		$this->response->body(json_encode($ret_array));
	}
	public function action_get_edit_milestone($id)
	{
		$data['milestone'] = Model::factory('milestone')->get_milestone($id);
		$data['users'] = Model::factory('user')->get_project_users($data['milestone']['project_id'], Helper_MyConst::IN_PROJECT);
		$edit_view = View::factory('/milestones/edit_milestone', $data);
		$this->response->body($edit_view);
	}
	public function action_edit_milestone($mile_id)
	{
		$cur_user_id = $_GET['cur_user_id'];
		$this->response->body(json_encode(array(
			'success' => TRUE,
			'data'	 => array(
				'id'			=> 1,
				'name' => 'Sau khi sua milestone', 
				'deadline' => $_GET['deadline'],
				'cur_user_id'	=> 1,
			)
		)));
	}
	public function action_get_pre_milestone()
	{
		$next_milestones = array(
		 	0 => array(
		 		'date_create' 	=> '2011-12-19',
		 		'name'		  	=> 'Test 1',
		 		'status'		=> Helper_MyConst::STATUS_COMPLETE,
		 	),
		 	1 => array(
		 		'date_create' 	=> '2011-12-22',
		 		'name'		  	=> 'Test 2',
		 		'status'		=> Helper_MyConst::STATUS_IN_PROGRESS,
		 	),
		 	2 => array(
		 		'date_create' 	=> '2011-12-23',
		 		'name'		  	=> 'Test 3',
		 		'status'		=> Helper_MyConst::STATUS_IN_PROGRESS,
		 	),
		 );	
		 $this->response->body(json_encode(array(
			'success' => TRUE,
			'data'	 => $next_milestones
		)));
	}
	public function action_get_next_milestone()
	{
		$next_milestones = array(
		 	0 => array(
		 		'date_create' 	=> '2011-12-19',
		 		'name'		  	=> 'Test 1',
		 		'status'		=> Helper_MyConst::STATUS_COMPLETE,
		 	),
		 	1 => array(
		 		'date_create' 	=> '2011-12-22',
		 		'name'		  	=> 'Test 2',
		 		'status'		=> Helper_MyConst::STATUS_IN_PROGRESS,
		 	),
		 	2 => array(
		 		'date_create' 	=> '2011-12-23',
		 		'name'		  	=> 'Test 3',
		 		'status'		=> Helper_MyConst::STATUS_IN_PROGRESS,
		 	),
		 );	
		 $this->response->body(json_encode(array(
			'success' => TRUE,
			'data'	 => $next_milestones
		)));
	}
}